from collections import Counter
from math import sqrt

def frequency(data):
    """频率"""
    counter = Counter(data)
    ret = []
    print(counter.most_common()[0][1])
    for point in counter.most_common():
        ret.append((point[0],point[1]/len(data)))
    return ret

def mode(data):
    """众数"""
    counter = Counter(data)
    if counter.most_common()[0][1] == 1:
        return None,None

    count = counter.most_common()[0][1]
    ret = []
    for  point in counter.most_common():
        if point[1] == count:
            ret.append(point[0])
        else:
            break
    return ret,count
def median(data):
    """中位数"""
    sort_data = sorted(data)
    n = len(data)
    if n % 2 == 1:
        return sort_data[n // 2]
    return (sort_data[n // 2 - 1] + sort_data[n //2]) / 2
def mean(data):
    """均值"""
    return sum(data) / len(data)

def range(data):
    """极差"""
    return max(data) - min(data)

def quartile(data):
    """四分位数"""
    n = len(data)
    q1,q2,q3 = None,None,None
    if n < 4:
        return None,None,None
    sort_data = sorted(data)
    q2 = median(sort_data)
    if n % 2 == 1:
        q1 = median(sort_data[:(n // 2)])
        q3 = median(sort_data[(n // 2 + 1):])
    else:
        q1 = median(sort_data[:(n // 2)])
        q3 = median(sort_data[(n // 2):])
    return q1,q2,q3
def variance(data):
    """方差"""
    n = len(data)
    if n <= 1:
        return None
    mean_value = mean(data)
    return sum((e - mean_value) ** 2 for e in data) / (n - 1)
def std(data):
    """标准差"""
    return sqrt(variance(data))
